package com.example.mediaplayer_demo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;

public class MusicAdapter extends ArrayAdapter {
    private final int resourceId;
    public MusicAdapter(@NonNull Context context, int resource, List<MusicInfo> musicInfos) {
        super(context, resource,musicInfos);
        resourceId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        MusicInfo musicInfo = (MusicInfo) getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId, null);
        TextView musicId =  view.findViewById(R.id.music_id);
        TextView musicName = view.findViewById(R.id.music_name);
        musicId.setText(musicInfo.getId());
        musicName.setText(musicInfo.getName());
        return view;
    }
}
